package com.alvis.media.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // ✅ 显式指定物理路径（必须带 file: 前缀）
        String uploadPath = "file:E:/java_qimo/media-analysis-system_1/target/classes/static/uploads/";

        System.out.println("✅ WebMvcConfig 已加载到 Spring 容器");
        System.out.println("✅ 静态资源目录选用: " + uploadPath);

        // 映射 AI 分析图片目录
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations(uploadPath)
                .setCachePeriod(0);

        // ✅ 补充 Spring Boot 默认静态资源映射
        registry.addResourceHandler("/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/",
                        "classpath:/resources/",
                        "classpath:/static/",
                        "classpath:/public/"
                );
    }
}
